<?php
class GroupsController extends AppController {

	var $name = 'Groups';

	function admin_index() {
		$this->Group->recursive = 1;
		$this->set('groups', $this->paginate());
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Group->create();
			if ($this->Group->save($this->data)) {
				$this->Session->setFlash(__('GROUPS_SAVED_OK',true));
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash(__('GROUPS_SAVED_ERROR',true));
			}
		}
	}

	function admin_edit($id = null) {
		if (!$this -> Group -> findById($id)) {
			$this->Session->setFlash(__('GROUPS_INVALID',true));
			$this->redirect(array('action'=>'index'), null, true);
		}
		if (!empty($this->data)) {
			if ($this->Group->save($this->data)) {
				$this->Session->setFlash(__('GROUPS_SAVED_OK',true));
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash(__('GROUPS_SAVED_ERROR',true));
			}
		} else {
			$this->data = $this->Group->read(null, $id);
		}
	}

	function admin_delete($id = null) {
		if (!$this -> Group -> findById($id)) {
			$this->Session->setFlash(__('GROUPS_INVALID',true));
		}
		if ($this->Group->del($id)) {
			$this->Session->setFlash(__('GROUPS_DELETED_OK',true));
		}
		$this->redirect(array('action'=>'index'), null, true);
	}

	function admin_delete_groups(){
		if($this -> Group -> deleteAll(array('Group.id'=>$this -> data['GroupsDelete']))) {
			$this->Session->setFlash(__('GROUPS_DELETED_OK',true));
		} else {
			$this->Session->setFlash(__('GROUPS_DELETED_ERROR',true));
		}
		$this->redirect(array('action'=>'index'), null, true);
	}
}
?>